home *** CD-ROM | disk | FTP | other *** search
- /* $VER: Connect 1.51 (30.10.96) (c) Neil Bothwick */
- /* */
- /* Connects your Amiga to the Internet, optionally */
- /* fetching news or mail and logging off again */
- /* :
- Name
- Connect
-
- Usage
- Connect [MAIL|NEWS|AUTOMAIL|AUTONEWS|OFF|AUTOOFF]
-
- Options
- None: Connects to Internet
- MAIL: Connects to Internet and fetches mail
- NEWS: Connects to Internet and fetches news and mail
- AUTOMAIL: Connects to Internet, fetches mail and disconnects
- AUTONEWS: Connects to Internet, fetches news and mail and disconnects
- OFF: Disconnects from Internet
- AUTOOFF: Disconnects from Internet after waiting for news and mail to finish
-
- */
- ;;
- /* :These are specific to your setup */
-
- DevName = 'DEVS:Networks/ppp.device' /* Your network device */
- DevUnit = 0 /* its unit number */
- Interface = 'ppp'||DevUnit /* Interface name */
- ;;
- /* :Don't change anything below here */
-
- if ~show('L','rexxsupport.library') then /* Load the libraries */
- if ~addlib('rexxsupport.library',0,-30) then exit
-
- if ~show('L','rexxdossupport.library') then
- if ~addlib('rexxdossupport.library',0,-30) then exit
-
- if ~show('L','rexxreqtools.library') then
- if ~addlib('rexxreqtools.library',0,-30) then exit
-
- BinPath = 'AmiTCP:bin/' /* Paths to AmiTCP commands */
- ThorPath = GetVar('Thor/ThorPath')
- Miami = 'AmiTCP:Miami'
- StartNet = BinPath||'StartNet'
- ifconfig = BinPath||'ifconfig'
- route = BinPath||'route'
- online = BinPath||'online'
- offline = BinPath||'offline'
- resolve = BinPath||'resolve'
- SendEvents = BinPath||'SendEvents'
- GetMail = BinPath||'Fetch Mail'
- GetNews = BinPath||'Fetch All'
- LogPath = 'UUSpool:Connect.log'
- SendProc = ThorPath||'bin/SendTCP' /* CLI process names for news and mail */
- GetProc = ThorPath||'bin/GetTCP'
- Unbatch = BinPath||'ParseThor'
- ;;
- options results
- address command
- arg opt
-
- /* :Main routine */
- if exists('ENV:Wirenet/UseMiami') then UseMiami = 1
- else UseMiami = 0
-
- if GetVar('IPADDRESS') = '0.0.0.0' then AcctType = 'Dynamic'
- else AcctType = 'Static'
-
- select
- when opt = '' then call Connect
- when opt = 'MAIL' then do
- call Connect
- call DoMail
- end
- when opt = 'NEWS' then do
- call Connect
- call DoNews
- end
- when opt = 'AUTOMAIL' then do
- call Connect
- call DoMail
- call Auto
- call Disconnect
- end
- when opt = 'AUTONEWS' then do
- call Connect
- call DoNews
- call Auto
- call Disconnect
- end
- when opt = 'OFF' then call Disconnect
- when opt = 'AUTOOFF' then do
- call Auto
- call Disconnect
- end
- otherwise call BadArgs
- end
- ;;
- exit
-
- /* Procedures */
-
- /* :Establish connection */
- Connect:
- StartNet
- if exists('AmiTCP:db/User-PreConnect') then address command 'AmiTCP:db/User-PreConnect'
- if UseMiami = 0 then do
- call MakeDialScript()
- online Interface
- if RC > 0 then call ConnectionFailed
- ifconfig 'lo0 localhost'
- ifconfig Interface '$ppp0IPLocal $ppp0IPRemote'
- if AcctType = 'Dynamic' then do /* Set up for dynamic account */
- address 'AMITCP' 'ADD HOST $ppp0IPLocal $HostName'
- route 'add $ppp0IPLocal localhost'
- end
- route 'add default $ppp0IPRemote'
- call WriteLog('Connection made to' GetVar('ppp0IPRemote'))
- end
- else do
- address 'MIAMI.1' 'ONLINE'
- address 'MIAMI.1' 'ISONLINE'
- if RC = 0 then call ConnectionFailed
- call WriteLog('Connection made')
- end
- 'SetEnv NetState Online'
- if exists('AmiTCP:db/User-PostConnect') then address command 'AmiTCP:db/User-PostConnect'
- 'run >UUSpool:SendEvents.debug' SendEvents
- Wait 2
- return
- ;;
- /* :Break connection */
- Disconnect:
- if exists('AmiTCP:db/User-PreDisconnect') then address command 'AmiTCP:db/User-PreDisconnect'
- if UseMiami = 0 then do
- ifconfig interface 'down'
- offline Interface
- route 'delete >NIL: $ppp0IPLocal'
- route 'delete >NIL: default'
- end
- else do
- address 'MIAMI.1' 'OFFLINE'
- end
- call WriteLog('Connection closed')
- 'unsetenv FetchState'
- 'SetEnv NetState Offline'
- Unbatch
- if exists('AmiTCP:db/User-PostDisconnect') then address command 'AmiTCP:db/User-PostDisconnect'
- return
- ;;
- /* :Start mail download */
- DoMail:
- 'run >NIL:' GetMail
- call WriteLog('Mail download started')
- return
- ;;
- /* :Start mail and news download */
- DoNews:
- 'Run >NIL:' GetNews
- call WriteLog('News download started')
- return
- ;;
- /* :Wait for mail and news processes to stop */
- Auto:
- say 'Waiting for news/mail to finish'
- Wait 4
- call WaitToEnd(SendProc GetProc)
- Wait 2
- call WaitToEnd(SendProc GetProc)
- return
- ;;
- /* :Give usage information */
- BadArgs:
- say
- say 'Usage: Connect [MAIL|NEWS|AUTOMAIL|AUTONEWS|OFF|AUTOOFF]'
- say
- say ' None: Connects to Internet'
- say ' MAIL: Connects to Internet and fetches mail'
- say ' NEWS: Connects to Internet and fetches news and mail'
- say ' AUTOMAIL Connects to Internet, fetches mail and disconnects'
- say ' AUTONEWS: Connects to Internet, fetches news and mail and disconnects'
- say ' OFF: Disconnects from Internet'
- say ' AUTOOFF: Disconnects from Internet after waiting for news and mail to finish'
- say
- exit
- ;;
- /* :Write line in logfile */
- WriteLog: procedure expose LogPath
- parse arg msg
- LogEntry = left(date('W'),3) date() time() msg
- say LogEntry
- if ~open(log,LogPath,'A') then do
- if ~open(log,LogPath,'W') then return
- end
- call writeln(log,LogEntry)
- call close(log)
- return
- ;;
- /* :Wait for the specified process to finish */
- WaitToEnd: procedure
- parse arg Processes
-
- procs = words(Processes)
- do i = 1 to procs
- parse var Processes Process.i Processes
- end
-
- do until Busy = FALSE
- Busy = FALSE
- do i = 1 to procs
- 'Status >NIL: com='Process.i
- if RC = 0 then do
- Busy = TRUE
- Wait 3
- end
- end
- end
- return
- ;;
- /* :Report connection failure */
- ConnectionFailed:
- call WriteLog('Connection attempt failed')
- ExitMsg('Your internet connection has failed')
- return
- ;;
- /* :Exit with message */
- ExitMsg:
- parse arg ErrMsg
- say(ErrMsg)
- exit
- return
- ;;
- /* :Create dialscript and ppp0.config */
- MakeDialScript:
- /* Create DialScript */
- if ~open('ds','ENV:Wirenet/DialScript','W') then call ExitMsg('Failed to create dialscript')
- call writeln('ds','# Dialer Script (change to echo off if you do not want echoing)')
- call writeln('ds','echo on')
- call writeln('ds','abort "NO DIALTONE"')
- call writeln('ds','redial "BUSY" "NO CARRIER" "NO ANSWER"')
- call writeln('ds','redialdelay 300')
- call writeln('ds','timeout 500')
- call writeln('ds','# Initialise modem...')
- call writeln('ds','send "'||GetVar('Wirenet/ModemInit')||'"')
- call writeln('ds','wait "OK"')
- call writeln('ds','delay 15')
- call writeln('ds','# Send dial command...')
- call writeln('ds','send "'||GetVar('Wirenet/ModemDial')||GetVar('Wirenet/PoPNum')||'"')
- call writeln('ds','# ... and wait for connection.')
- call writeln('ds','timeout 1600')
- call writeln('ds','wait "CONNECT"')
- if ~exists('ENV:Wirenet/UsePAP') then do
- call writeln('ds','send ""')
- call writeln('ds','# At login: prompt send nodename')
- call writeln('ds','wait "ogin:"')
- call writeln('ds','send "'||GetVar('NODENAME')||'"')
- call writeln('ds','# At Password: prompt send password')
- call writeln('ds','wait "assword:"')
- call writeln('ds','echo off')
- call writeln('ds','send "'||subword(GetVar('Wirenet/pap.config'),2)||'"')
- call writeln('ds','echo on')
- call writeln('ds','# Wait for Service: prompt and then send PPP')
- call writeln('ds','wait "ervice:"')
- call writeln('ds','send "PPP"')
- call writeln('ds','# Wait for start string')
- call writeln('ds','wait "MTU"')
- call writeln('ds','send " "')
- call writeln('ds','# Connected!')
- end
- call close('ds')
-
- /* Create PPP config file */
- if ~open(pppcfg,'ENV:sana2/ppp0.config','w') then ExitMsg('Failed to create ppp configuration')
- call writech(pppcfg,GetVar('Wirenet/ModemDev')' ')
- call writech(pppcfg,GetVar('Wirenet/ModemSpeed')' ')
- call writech(pppcfg,GetVar('IPADDRESS')' ')
- call writech(pppcfg,'DialScript ENV:Wirenet/DialScript ')
- call writech(pppcfg,'MTU='GetVar('Wirenet/MTU')' ')
- call writech(pppcfg,GetVar('Wirenet/ppp.options'))
- if exists('ENV:Wirenet/UsePAP') then call writech(pppcfg,' PAP=ENV:Wirenet/pap.config,'GetVar('NODENAME'))
- if exists('ENV:Wirenet/DialWindow') then call writech(pppcfg,' DIALWINDOW ' GetVar('Wirenet/DialWindow'))
- if exists('ENV:Wirenet/Gateway') then call writech(pppcfg,' REMOTEIP' GetVar('Wirenet/Gateway'))
- call close(pppcfg)
-
- return
- ;;
-
-